package com.example.yjhuser.controller;

import com.example.yjhuser.entity.Tiezi;
import com.example.yjhuser.service.TieziService;
import com.yc.yjh.entity.Result;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("tz")
public class TieziController {


    @Resource
    private TieziService tieziService;

    @RequestMapping("get")
    public Result getAllTz(){
        return Result.success("OK",tieziService.getAllTiezi());
    }

    @PostMapping("set")
    public Result setTz(@RequestBody Tiezi tiezi){
        return Result.success("OK",tieziService.setTiezi(tiezi));
    }


    @GetMapping("getbyuid")
    public Result getAlltzByUid(String id){
        return Result.success("OK",tieziService.getAllTzByUid(id));
    }
    @GetMapping("byId")
    public Result getOneById(@RequestParam("id")String id){
        final Tiezi tieziById = tieziService.getTieziById(id);
        if (ObjectUtils.isEmpty(tieziById)){
            return Result.error("业务繁忙,请稍后再试!");
        }
        return Result.success("OK",tieziById);
    }

    @GetMapping("/del")
    public Result delTzById(@RequestParam("id")String id){
        final int i = tieziService.delTiezById(id);
        if (i>0){
            return Result.success("删除成功");
        }else {
            return Result.error("请求超时");
        }
    }
}
